package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsUserMapper;
import com.qf.pojo.DtsUser;
import com.qf.service.UserService;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private DtsUserMapper dtsUserMapper;
    @Override
    public Long findUsersCount() {
        return dtsUserMapper.selectCount(null);
    }

    @Override
    public List<DayStatis> findDayStatis() {
        return dtsUserMapper.findDayStatis();
    }

    @Override
    public IPage<DtsUser> findUserByQuery(Integer page, Integer limit, String username, String mobile, String sort, String order) {
        return dtsUserMapper.selectPage(new Page<>(page,limit),
                new QueryWrapper<DtsUser>()
                        .like(!StringUtils.isEmpty(username),"username",username)
                        .eq(!StringUtils.isEmpty(mobile),"mobile",mobile)
                        .eq("deleted",false)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),"id"));
    }

    @Override
    public List<Integer> findIdByUsernameAndMobile(String username, String mobile) {
        List<Integer> uIds = dtsUserMapper.findIdByUsernameAndMobile(username,mobile);
        return uIds;
    }




}
